package com.df.happylearn.utils;

import android.content.Context;

import com.df.happylearn.application.MyApplication;
import com.df.happylearn.cache.ACache;

import java.io.File;

public class CacheUtil {

    private Context mContext;
    private ACache mMessageCache;
    private ACache mArticleContentCache;

    private static CacheUtil cacheUtil;

    private CacheUtil() {
        mContext = MyApplication.getInstance();
    }

    public static CacheUtil getInstance() {
        if (cacheUtil == null) {
            cacheUtil = new CacheUtil();
        }
        return cacheUtil;
    }

    public ACache getArticleContentCache() {
        if (mArticleContentCache == null) {
            String cachePath = mContext.getCacheDir().getPath() + "/article-cache/";
            File file = new File(cachePath);
            if (!file.exists()) {
                file.mkdirs();
            }
            mArticleContentCache = ACache.get(file);
        }
        return mArticleContentCache;
    }

    public ACache getMessageCache() {
        if (mMessageCache == null) {
            String cachePath = mContext.getCacheDir().getPath() + "/message-cache/";
            File file = new File(cachePath);
            if (!file.exists()) {
                file.mkdirs();
            }
            mMessageCache = ACache.get(file);
        }
        return mMessageCache;
    }


}
